// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ListBoxItemsMover.cs" company="GT">
//   Gunther Taborga
// </copyright>
// <summary>
//   Defines the ListBoxItemsMover type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

// TODO refactored=true
namespace BatchID3.Editor.Controls
{
    using System.Collections.ObjectModel;
    using System.Windows.Controls;

    internal class ListBoxItemsMover
    {
        private readonly ListBox listBox;

        public ListBoxItemsMover(ListBox listBox)
        {
            this.listBox = listBox;
        }

        public void MoveUp<T>(ObservableCollection<T> listItems)
        {
            if (this.listBox.SelectedItems.Count != 1)
            {
                return;
            }

            var selectedIndex = this.listBox.SelectedIndex;

            if (selectedIndex <= 0)
            {
                return;
            }

            listItems.Move(selectedIndex, --selectedIndex);
            this.listBox.SelectedIndex = selectedIndex;
        }

        public void MoveDown<T>(ObservableCollection<T> listItems)
        {
            if (this.listBox.SelectedItems.Count != 1)
            {
                return;
            }

            var selectedIndex = this.listBox.SelectedIndex;

            if (selectedIndex >= this.listBox.Items.Count - 1)
            {
                return;
            }

            listItems.Move(selectedIndex, ++selectedIndex);
            this.listBox.SelectedIndex = selectedIndex;
        }
    }
}